// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import axios from 'axios'
import Vue from 'vue'
import VueAxios from 'vue-axios'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import db from './vendor/datastore'

import App from './App'
import router from './router'

Vue.use(VueAxios, axios)
Vue.use(ElementUI)
Vue.prototype.$db = db
Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('token') || ''

  // 配置接口信息
  // Axios.defaults.baseURL = api.rootUrl
  // Axios.defaults.headers.common['X-Nideshop-Token'] = token

  if (!token && to.name !== 'login') {
    next({
      path: '/login',
      query: {redirect: to.fullPath}
    })
  } else {
    next()
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
